<template>
  <el-container class="login-one">
    <el-header></el-header>
    <el-main>
          <el-row>
              <el-col :span="8">&nbsp;</el-col>
              <el-col :span="8">
                <br><br><br><br><br><br>
                      <el-form label-width="80px" style="background-color: white;border-radius: 3%">
                        <br>
                        <h1 align="center">用户登录</h1>

                             <el-form-item label="用户名">
                                <el-col :span="20">
                                    <el-input v-model="user.userName" ></el-input>
                                </el-col>
                              </el-form-item>

                          <el-form-item label="密码">
                            <el-col :span="20">
                              <el-input v-model="user.userPwd" show-password></el-input>
                            </el-col>
                          </el-form-item>

                          <el-form-item>
                              <el-col :span="6">&nbsp;</el-col>
                              <el-col :span="10">
                                <el-button type="success" icon="el-icon-s-custom" size="mini" @click="login">登录</el-button>
                                <el-button type="success" icon="el-icon-remove" size="mini">重置</el-button>
                              </el-col>
                              <el-col :span="8">&nbsp;</el-col>
                          </el-form-item>
                      </el-form>
              </el-col>
              <el-col :span="8">&nbsp;</el-col>
          </el-row>
    </el-main>
  </el-container>

</template>

<script>
    export default {
        name: "Login",
        data(){
           return{
               user:{
                  userName:"cat01",
                  userPwd:"123"
               }
           }
        },
        methods:{
              login(){
                const self = this;
                this.$http.post("/server-exam-system/user-info/user/1",
                   this.user)
                  .then(function (rs) {
                     console.log(rs.data);
                     if(rs.data.code==200){
                        //用replace禁止用户后退功能
                        self.$router.replace("/index");
                       //存入本地存储
                       localStorage.setItem("token",rs.data.data);
                       //存入用户名
                       localStorage.setItem("name",self.user.userName);
                     }

                  })

              }
        }
    }
</script>

<style scoped>
  @import url('../../assets/css/index.css');


</style>
